package com.bdhub.Main;

import com.bdhub.handld.ClientBootstrap;
import com.bdhub.im.server.protobuf.MessageProtobuf.CMsg;
import com.bdhub.interfaces.EventListener;

import java.util.Date;
import java.util.Vector;

public class LibMain {
	public static void main(String[] args) {
//		try {
//			final LibMain libMain= new LibMain();
//			// MsgFailedListener mfl = new MsgFailedListener();
//			// mfl.addListener(new EventListener(){
//			// @Override
//			// public void handleEvent(Message source)
//			// {
//			// System.out.println("[Client CALLBACK] " +
//			// source.getHead().getType());
//			// }
//			// });
//
//			// build listener
////			final EventListener listener= new EventListener() {
////				@Override
////				public void handleEvent(Message source) {
////					System.out.println("[Client CALLBACK] "
////							+ source.getHead().getType()+ " time :"+new Date(System.currentTimeMillis()));
////				}
////
////				@Override
////				public boolean isNetworkConnected() {
////					return true;
////				}
////			};
//			//
//
//			// server address list
////			final Vector<String> addrs = new Vector<String>();
////			// addrs.addElement("test.ihuoliao.com 8989");
////			// addrs.addElement("test.ihuoliao.com 8990");
////			addrs.addElement("203.195.217.166 8989");
////			// addrs.addElement("203.195.217.166 8990");
////			//
////
////			//
////			final NetStatusHandle nsh = new NetStatusHandle();
////
////			final ClientBootstrap bootstrap = ClientBootstrap.getInstance();
//////			bootstrap.setNetStatus(true);
////			bootstrap.init(addrs, listener, "100015",
////					"14cc329c1960419388921590619f6360", nsh);
////			ExecutorService pool = Executors.newFixedThreadPool(10);
//			// Thread.sleep(500);
////			for (int i = 0; i < 10; i++) {
////				final int index = i;
////				// try {
////				// Thread.sleep(500);
////				// } catch (InterruptedException e) {
////				// // TODO Auto-generated catch block
////				// e.printStackTrace();
////				// }
////				pool.execute(new Runnable() {
////					@Override
////					public void run() {
////						if (index == 8) {
////							System.out.println("关闭..."
////									+ System.currentTimeMillis());
////							bootstrap.close();
////						} else if (index == 9) {
//////							try {
//////								Thread.sleep(1000);
//////							} catch (InterruptedException e) {
//////								e.printStackTrace();
//////							}
////							libMain.init();
////						} else {
////							ClientBootstrap.getInstance().setNetFlag(-1);
////							try {
////								Thread.sleep(500);
////							} catch (InterruptedException e) {
////								e.printStackTrace();
////							}
////						}
////
////					}
////				});
////			}
////			Thread.sleep(1000);
//			long b= System.currentTimeMillis();
//		
//			//bootstrap.close();
////			System.out.println(System.currentTimeMillis() -b );
////	    Thread.sleep(100);
//			libMain.init();
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}

	void init(){
		final EventListener listener= new EventListener() {
			@Override
			public void handleEvent(CMsg source) {
				System.out.println("[Client CALLBACK] "
						+ source.getHead().getType()+ " time :"+new Date(System.currentTimeMillis()));
			}

			@Override
			public boolean isNetworkConnected() {
				return true;
			}
		};
		//

		// server address list
		final Vector<String> addrs = new Vector<String>();
		// addrs.addElement("test.ihuoliao.com 8989");
		// addrs.addElement("test.ihuoliao.com 8990");
		addrs.addElement("203.195.217.166 8989");
		// addrs.addElement("203.195.217.166 8990");
		//

		//
		final NetStatusHandle nsh = new NetStatusHandle();

		final ClientBootstrap bootstrap = new ClientBootstrap();
//		bootstrap.setNetStatus(true);
		bootstrap.init(addrs, listener, "100015",
				"14cc329c1960419388921590619f6360", nsh);
//		ClientBootstrap.getInstance().init(addrs, list,
//				"100015",
//				"14cc329c1960419388921590619f6360", nsh);
	}
}
